<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1">
    <title>jQuery Mobile Web 应用程序</title>

    <!-- css -->
    <link href="css/jquery.mobile-1.4.0.min.css" rel="stylesheet" type="text/css"/>
    <link href="css/my.css" rel="stylesheet" type="text/css"/>
    <link href="css/myScroll.css" rel="stylesheet" type="text/css" media="all"/>
    <link href="css/jquery.toastmessage.css" rel="stylesheet" type="text/css">

    <!-- js -->

    <script src="js/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script src="js/jquery.mobile-1.4.0.min.js" type="text/javascript"></script>
    <script src="js/iscroll.js" type="text/javascript"></script>
    <script src="js/jquery.toastmessage.js" type="text/javascript"></script>
    <script src="js/aqyh.js" type="text/javascript"></script>
    <script src="js/login.js" type="text/javascript"></script>
    <script type="text/javascript" src="cordova.js"></script>
    <script src="js/webintent.js" type="text/javascript"></script>

    <script type="text/javascript">
    var loading = false;

        $(function () {
            $.ajax({
                url: serverPath + "yhEnter/pcPerson",
                dataType: "jsonp",
                type: "post",
                jsonpCallback: "pcPerson",
                success: function (data) {
                    if (data != undefined && data != null && data != "null") {
                        $("#loginUser").text("欢迎：" + data.personName);
                    }
                },
                error: function () {
                    alert("error!");
                }
            });
        });

        function openAndroidActivity() {
            window.plugins.webintent.openApk({
                        action: "android.intent.action.VIEW",
                        url: 'http://10.1.168.50:8080/res/airimos_phone_android.apk'},
                    function () {
                    },
                    function () {
//                        alert('无法打开视频监控，请先安装客户端！');
                        window.plugins.webintent.startActivity({
                                    action: "android.intent.action.VIEW",
                                    url: 'http://10.1.168.50:8080/res/airimos_phone_android.apk'},
                                function () {
                                },
                                function () {
                                    alert('下载客户端出错！');
                                }
                        );
                    }
            );

        }

        function startMyActivity() {
            window.plugins.webintent.myStartActivity({
                        action: "android.intent.action.VIEW",
                        url: 'http://10.1.168.50:8080/res/airimos_phone_android.apk'},
                    function () {
                    },
                    function () {
                        alert('出错！');
                    }
            );
        }

        function getZbdbld() {
            if (loading == false) {
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();

                if (month < 10) {
                    month = "0" + month;
                }
                if (day < 10) {
                    day = "0" + day;
                }

                var curDate = year + "-" + month + "-" + day;

//            alert(curDate);

                var testDate = "2013-10-22";

                $.mobile.loading("show", {text: "正在获取...", textVisible: true});
                loading = true;

                $.ajax({
                    url: "http://58.242.43.42:8010/DataService/summary/zbdbld/date/" + curDate,
                    dataType: "jsonp",
                    type: "post",
                    timeout: 10000,
                    jsonpCallback: "zbdbld",
                    success: function (data) {
                        if (data != undefined && data != null && data.length > 0) {
                            $.mobile.changePage("zbdbld.html");

                            setTimeout(function () {
                                $("#zbdbld-result tbody").html("");

                                for (var i = 0; i < data.length; i++) {

                                    var tableStr = "<tr>";
                                    tableStr += "<td rowspan='4'>" + data[i].deptName + "</td>";
                                    tableStr += "<td colspan='2'>值班</td>";
                                    tableStr += "<td>" + data[i].detail + "</td></tr>";

                                    tableStr += "<tr>";
                                    tableStr += "<td rowspan='3'>带班</td>";
                                    tableStr += "<td>夜班</td>";
                                    tableStr += "<td>" + data[i].yb + "</td></tr>";

                                    tableStr += "<tr>";
                                    tableStr += "<td>早班</td>";
                                    tableStr += "<td>" + data[i].zb + "</td></tr>";

                                    tableStr += "<tr>";
                                    tableStr += "<td>中班</td>";
                                    tableStr += "<td>" + data[i].zhb + "</td></tr>";

                                    $(tableStr).appendTo($("#zbdbld-result tbody"));
                                }

                                // 刷新table, 否则隐藏coloumn功能不可用
                                $("#zbdbld-result").table("refresh");
                            }, 200);

                        } else {
                            $().toastmessage('showToast', {
                                text: '没有数据',
                                sticky: false,
                                position: 'middle-center',
                                type: 'notice'
                            });
                        }

                        $.mobile.loading("hide");
                        loading = false;
                    },
                    error: function () {
                        $.mobile.loading("hide");
                        loading = false;

                        $().toastmessage('showToast', {
                            text: '访问服务器错误！',
                            sticky: false,
                            position: 'middle-center',
                            type: 'error'
                        });
                    }
                });
            }

        }

        function getAqgk() {
            if (loading == false) {
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();

                if (month < 10) {
                    month = "0" + month;
                }
                if (day < 10) {
                    day = "0" + day;
                }

                var curDate = year + "-" + month + "-" + day;

                var testDate = "2013-10-22";

                $.mobile.loading("show", {text: "正在获取...", textVisible: true});
                loading = true;

                $.ajax({
                    url: "http://58.242.43.42:8010/DataService/aqgk/" + curDate,
                    dataType: "jsonp",
                    type: "post",
                    timeout: 10000,
                    jsonpCallback: "aqgk",
                    success: function (data) {
                        if (data != undefined && data != null && data.length > 0) {
                            $.mobile.changePage("aqgk.html");

                            setTimeout(function () {
                                $("#aqgk-result tbody").html("");

                                for (var i = 0; i < data.length; i++) {
                                    var tableStr = "<tr>";
                                    tableStr += "<td>" + data[i].deptName + "</td>";
                                    tableStr += "<td>" + data[i].yhAll + "</td>";
                                    tableStr += "<td>" + data[i].swAll + "</td>";
                                    tableStr += "<td>" + data[i].gpAll + "</td>";
                                    tableStr += "</tr>";

                                    $(tableStr).appendTo($("#aqgk-result tbody"));
                                }

                                // 刷新table, 否则隐藏coloumn功能不可用
                                $("#aqgk-result").table("refresh");
                            }, 200);
                        } else {
                            $().toastmessage('showToast', {
                                text: '没有数据',
                                sticky: false,
                                position: 'middle-center',
                                type: 'notice'
                            });
                        }

                        $.mobile.loading("hide");
                        loading = false;

                    },
                    error: function () {
                        $.mobile.loading("hide");
                        loading = false;

                        $().toastmessage('showToast', {
                            text: '访问服务器错误！',
                            sticky: false,
                            position: 'middle-center',
                            type: 'error'
                        });
                    }
                });
            }

        }

    function getRydwSummary() {
        if (loading == false) {
            $.mobile.loading("show", {text: "正在获取...", textVisible: true});
            loading = true;

            $.ajax({
                url: serverPath + "rydw/summary",
                dataType: "jsonp",
                type: "post",
                timeout: 10000,
                jsonpCallback: "rydwSummary",
                success: function (data) {
                    if (data != undefined && data != null && data.length > 0) {
                        $.mobile.changePage("rydw.html");

                        setTimeout(function () {
                            $("#rydw-result tbody").html("");

                            for (var i = 0; i < data.length; i++) {
                                var tableStr = "<tr>";
                                tableStr += "<td>" + data[i].shortName + "</td>";
                                tableStr += "<td>" + data[i].maxNum + "</td>";
                                tableStr += "<td>" + data[i].numMine + "</td>";
                                tableStr += "</tr>";

                                $(tableStr).appendTo($("#rydw-result tbody"));
                            }

                            // 刷新table, 否则隐藏coloumn功能不可用
                            $("#rydw-result").table("refresh");
                        }, 200);
                    } else {
                        $().toastmessage('showToast', {
                            text: '没有数据',
                            sticky: false,
                            position: 'middle-center',
                            type: 'notice'
                        });
                    }

                    $.mobile.loading("hide");
                    loading = false;

                },
                error: function () {
                    $.mobile.loading("hide");
                    loading = false;

                    $().toastmessage('showToast', {
                        text: '访问服务器错误！',
                        sticky: false,
                        position: 'middle-center',
                        type: 'error'
                    });
                }
            });
        }
    }
    </script>
</head>
<body>

<div data-role="page" id="main">
    <div data-role="header" data-theme="b">
        <div align="center"><h1 style="font-size: large">风险预控可视化系统</h1></div>
    </div>
    <div data-role="content">
        <div align="right">
            <span style="color: blue" id="loginUser"></span>
            <a href="#" onclick="logout()">退出系统</a>
        </div>

        <div class="ui-grid-b">
            <div class="ui-block-a" align="center">
                <a id="button1" class="myButton" href="#" data-role="button" style="background-image:url(logo/1.jpg);"
                   onclick="getZbdbld()">
                </a>
                带班值班
            </div>
            <div class="ui-block-b" align="center">
                <a id="button2" class="myButton" href="#" data-role="button"
                   style="background-image: url(logo/2.jpg)" onclick="getAqgk()"></a>
                安全概况
            </div>
            <div class="ui-block-c" align="center">
                <a id="button3" class="myButton" data-ajax="false" href="enterMain.html" data-role="button"
                   style="background-image: url(logo/3.jpg)"></a>
                信息录入
            </div>
            <div class="ui-block-a" align="center">
                <a id="button4" class="myButton" href="#" data-role="button"
                   style="background-image: url(logo/4.jpg)" onclick="getRydwSummary()"></a>
                人员定位
            </div>
            <div class="ui-block-b" align="center">
                <a id="button5" class="myButton" href="#" data-role="button" onclick="startMyActivity()"
                   style="background-image: url(logo/5.jpg)"></a>
                视频监控
            </div>
            <div class="ui-block-c" align="center">
                <a id="button6" class="myButton" data-ajax="false" href="aqyh.html" data-role="button"
                   style="background-image: url(logo/6.jpg)"></a>
                隐患三违
            </div>
            <div class="ui-block-a" align="center">
                <a id="button7" class="myButton" href="doc/doc.html" data-role="button"
                   style="background-image: url(logo/7.jpg)"></a>
                系统帮助
            </div>
            <div class="ui-block-b" align="center">
                <a id="button8" class="myButton" data-ajax="false" href="swxcQuery.html" data-role="button"
                   style="background-image: url(logo/8.jpg)"></a>
                抓拍记录
            </div>
            <div class="ui-block-c" align="center">
                <a id="button9" class="myButton" data-ajax="false" href="summary.html" data-role="button"
                   style="background-image: url(logo/9.jpg)"></a>
                统计分析
            </div>
        </div>
    </div>
</div>

</body>
</html>
